package com.kfm.base.io.o;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class Demo04 {

    public static void main(String[] args) {
        Singleton singleton = Singleton.getInstance();

        // 反射，运行时获取类信息
        Class<Singleton> singletonClass = Singleton.class;

        try {
            // 获取 构造函数
            Constructor<Singleton> constructor = singletonClass.getDeclaredConstructor();
            // 设置为 可访问
            constructor.setAccessible(true);

            Singleton singleton1 = constructor.newInstance();

            System.out.println(singleton1);
            System.out.println(singleton1 == singleton);
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        }


    }
}
